package functions.ems_process_service;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;

import com.beans.AuditProcessBean;
import com.beans.TaskBean;
import com.crc.mam.BaseCase;
import coms.Constants;
import coms.JSONToBean;
import frame.HttpHelper;


public class ClaimProcessTaskMgr extends BaseCase {
	private org.slf4j.Logger logger = LoggerFactory.getLogger(ClaimProcessTaskMgr.class);
	
	AuditProcessBean processBean;
	TaskBean taskBean;
	public AuditProcessBean getProcessBean() {
		return processBean;
	}

	public void setProcessBean(AuditProcessBean processBean) {
		this.processBean = processBean;
	}

	public TaskBean getTaskBean() {
		return taskBean;
	}

	public void setTaskBean(TaskBean taskBean) {
		this.taskBean = taskBean;
	}

	/**
	 * 通过报账单查询我的待处理任务
	 */
	public void findmytodo(String claimNo) {
		logger.info("通过报账单：" + claimNo + "查询我的待处理任务 ----- start-----------");
		String param = "{\"page\":{\"currentPage\":1,\"pageSize\":10,\"recordCount\":1},"
				+ "\"params\":{\"catalogyCodeList\":[],\"claimAountlest\":\"\",\"claimAountmost\":\"\",\"startapplyDate\":\"\",\"endapplyDate\":\"\","
				+ "\"result\":[{\"claimNo\":\""+claimNo+"\",\"getRemark\":\"\",\"ouCode\":\"\",\"submitter\":\"\",\"venderCode\":\"\",\"venderName\":\"\"}]},"
						+ "\"sortDTO\":{\"fieldName\":\"\",\"orderBy\":\"\"}}";
	
		String url = Constants.FIND_MY_TODO_URL;
    	try {
			result = HttpHelper.post(param, url);
			status = HttpHelper.isOk;
			logger.info("findmytodo--------"+ result);
			if(status) {
			  try {
			    JSONObject object = new JSONObject(result);
			    int t = object.getInt("total");
				if(t == 1) {
					JSONArray array = object.getJSONArray("list");
					JSONObject datas = array.getJSONObject(0);					
					 claimNo = "";
					 taskBean = JSONToBean.parseJson2Object(TaskBean.class, datas.toString());
					
					/**
					 * 存储process变量
					 */
					JSONArray processArray = datas.getJSONArray("processVariables");
					JSONObject processDatas = processArray.getJSONObject(0);
					processBean = JSONToBean.parseJson2Object(AuditProcessBean.class, processDatas.toString());
				   
				  }else {
				    status = false;
					remark = "没有找到需要审批的报账单 "+ claimNo;
					
				}
			  }catch(JSONException e) {
				e.printStackTrace();
				status = false;
				remark  = "JSON解析错误";
			  }
			}else {
			  try {
			    JSONObject object = new JSONObject(result);
			    remark = object.getString("message");
			  }catch(JSONException e) {
			    e.printStackTrace();
			    remark = "JSON解析错误";
			  }
			}
    	}catch(Exception e) {
    		e.printStackTrace();
    		status = false;
            remark  = "系统异常";
    	}
    	
    	logger.info("通过报账单：" + claimNo + "查询我的待处理任务 ----- end-----------");
	}
}
